package io;

import java.io.*;

/**
 * @author haomin
 * @date 2022/05/09 21:02
 **/
public class CopyDirectory {
    static String dir = "D:\\电影\\文件操作";
    static String goal = "D:\\电影\\文件操作2";
    public static void main(String[] args) throws IOException {
        File startDir = new File(dir);
        if(!startDir.isDirectory()){
            System.out.println("不是文件！");
            return;
        }
        File goalFile = new File(goal);
        traversal(startDir,goalFile);
    }

    private static void traversal(File startDir,File goalFile) throws IOException {
        File[] files = startDir.listFiles();
        if(files == null){
            return;
        }

        for(File file : files){
            if(file.isDirectory()){
                String path1 = file.getCanonicalPath();
                String relative = path1.substring(dir.length());
                String path2 = goal + relative;
                File file2 = new File(path2);
                file2.mkdirs();

                traversal(file,goalFile);
            }else if(file.isFile()) {

            }
        }
    }
}